version 14.2
set more off
set matsize 11000

***********************************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.II OF WASEEM (2020) ROLE OF WITHHOLDING ...
***********************************************************************************************************************

*-----------------------------------------------------------
* DROPS ALL FIRMS WHO EXPORT EVEN ONCE IN THE SAMPLE PERIOD
*-----------------------------------------------------------

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0);
#d				cr

/* ALL FIRMS */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
keep					if fy>1996 & fy<=2003
g						expo_temp=(exposale_ag>0)
bys						regnor:egen exporter=max(expo_temp)
drop					if exporter==1
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=1999)
g						treat_after=treat*after						
g						lnsales=log(purch_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=1997/2003 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* COLUMN 1 */

local					i=2
local					j=1
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[6,`j']=e(N)

/* COLUMN 2 */

local					i=2
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_1998 treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
local					i=`i'+2
matrix					table[`i',`j']=_b[treat_1998]
matrix					table[`i'+1,`j']=_se[treat_1998]
matrix					table[6,`j']=e(N)


/* BALANCED PANEL 2 */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep					if fy>1996 & fy<=2003
keep                	if business_sts=="1" | business_sts=="2"
g						expo_temp=(exposale_ag>0)
bys						regnor:egen exporter=max(expo_temp)
drop					if exporter==1
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g						quarter=qofd(taxperiod)
qui						sum quarter
replace					quarter=quarter-r(min)+1
qui						sum quarter
local					qmax=r(max)
g						filed=0
forvalues				q=1/`qmax' {
replace					filed=1 if quarter==`q'
}
bys						regno quarter:g first=_n==1
bys						regno:egen nqreturn=sum(first)
keep					if nqreturn==`qmax'
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=1999)
g						treat_after=treat*after						
g						lnsales=log(purch_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=1997/2003 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* COLUMN 3 */

local					i=2
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[6,`j']=e(N)

/* COLUMN 4 */

local					i=2
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_1998 treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
local					i=`i'+2
matrix					table[`i',`j']=_b[treat_1998]
matrix					table[`i'+1,`j']=_se[treat_1998]
matrix					table[6,`j']=e(N)


/* BALANCED PANEL */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep					if fy>1996 & fy<=2003
keep                	if business_sts=="1" | business_sts=="2"
g						expo_temp=(exposale_ag>0)
bys						regnor:egen exporter=max(expo_temp)
drop					if exporter==1
g						one=1
bys						regno:egen nreturns=sum(one)
qui						sum nreturns
keep					if nreturns==r(max)
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=1999)
g						treat_after=treat*after						
g						lnsales=log(purch_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=1997/2003 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* COLUMN 5 */

local					i=2
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[6,`j']=e(N)

/* COLUMN 6 */

local					i=2
local					j=`j'+1
qui						areg lnsales pdum2-pdum84 treat treat_1998 treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
local					i=`i'+2
matrix					table[`i',`j']=_b[treat_1998]
matrix					table[`i'+1,`j']=_se[treat_1998]
matrix					table[6,`j']=e(N)


*-----------------------------------------------------
* PLACEBO
*-----------------------------------------------------

/* ALL FIRMS */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep                	if business_sts=="1" | business_sts=="2"
keep					if fy>2003 & fy<=2010
g						expo_temp=(exposale_ag>0)
bys						regnor:egen exporter=max(expo_temp)
drop					if exporter==1
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=2006)
g						treat_after=treat*after						
g						lnsales=log(purch_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=2004/2010 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* COLUMN 1 */

local					i=8
local					j=1
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[10,`j']=e(N)

/* BALANCED PANEL 2 */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep					if fy>2003 & fy<=2010
keep                	if business_sts=="1" | business_sts=="2"
g						expo_temp=(exposale_ag>0)
bys						regnor:egen exporter=max(expo_temp)
drop					if exporter==1
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
g						quarter=qofd(taxperiod)
qui						sum quarter
replace					quarter=quarter-r(min)+1
qui						sum quarter
local					qmax=r(max)
g						filed=0
forvalues				q=1/`qmax' {
replace					filed=1 if quarter==`q'
}
bys						regno quarter:g first=_n==1
bys						regno:egen nqreturn=sum(first)
keep					if nqreturn==`qmax'
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=2006)
g						treat_after=treat*after						
g						lnsales=log(purch_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=2004/2010 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* COLUMN 3 */

local					i=8
local					j=`j'+2
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[10,`j']=e(N)

/* BALANCED PANEL */

use						"$project_data\STPAK_1996_2011_UBP_v1.dta", clear
keep					if fy>2003 & fy<=2010
keep                	if business_sts=="1" | business_sts=="2"
g						expo_temp=(exposale_ag>0)
bys						regnor:egen exporter=max(expo_temp)
drop					if exporter==1
g						one=1
bys						regno:egen nreturns=sum(one)
qui						sum nreturns
keep					if nreturns==r(max)
g						ind=real(substr(item_cd,1,4))
drop					if ind<1600
drop					if ind>=2500 & ind<2800
drop					period
g						period=mofd(taxperiod)
qui						sum period
replace					period=period-r(min)+1
g						treat=business_sts=="1"
g						after=(fy>=2006)
g						treat_after=treat*after						
g						lnsales=log(purch_ag)
qui						tab fy,g(fydum)
local 					i=1
forvalues 				y=2004/2010 {
g 							treat_`y'=treat*fydum`i'
							local i=`i'+1
}
qui						tab period, g(pdum)

/* COLUMN 5 */

local					i=8
local					j=`j'+2
qui						areg lnsales pdum2-pdum84 treat treat_after, absorb(regnor) cluster(ind)
matrix					table[`i',`j']=_b[treat_after]
matrix					table[`i'+1,`j']=_se[treat_after]
matrix					table[10,`j']=e(N)

/* FORMATTING TABLE */ 

svmat 			table
keep			tab*
drop			table7-table9
keep			if _n<=10
g				c11=""
replace			c11="\underline{A: 1997-2003}" in 1
replace			c11="$\mbox{\emph{Manuf}} \times \mbox{\emph{Post}}$" in 2
replace			c11="$\mbox{\emph{Manuf}} \times  1998$" in 4
replace			c11="Observations" in 6
replace			c11="\underline{B: 2004-2010}" in 7
replace			c11="$\mbox{\emph{Manuf}} \times \mbox{\emph{Post}}$" in 8
replace			c11="Observations" in 10
forvalues 		c=1/6 {
g				c`c'=string(table`c',"%9.3f")
}
foreach			r in 3 5 9 {
forvalues		c=1/6 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/6 {
replace			c`c'=string(table`c',"%15.0fc") in 6
replace			c`c'=string(table`c',"%15.0fc") in 10
}
forvalues		c=1/6 {
replace			c`c'="" in 1
replace			c`c'="" in 7
}
foreach			c in 1 3 5 {
forvalues		r=4/5 {
replace			c`c'="" in `r'
}
}
foreach			c in 2 4 6 {
forvalues		r=8/10 {
replace			c`c'="" in `r'
}
}
forvalues		s=1/8 {
g				s`s'="&"
}
g				l="\\"
foreach			r in 1 3 5 6 7 9 {
replace			l="\\\\" in `r'
}
order			c11 s8 c1 s1 c2 s2 s3 c3 s4 c4 s5 s6 c5 s7 c6 l
browse			c11 s8 c1 s1 c2 s2 s3 c3 s4 c4 s5 s6 c5 s7 c6 l

